<template>
    <div class="alDataBox">
        <template v-if="adPlaceJobRecordId">
            <div class="itembox">
                <div class="time"><span v-t="'analysis.title3'"></span> {{getTimes()}}</div>
                <div class="tabBox">
                    <span :class="{'selected':active==1}" @click="active=1;getPvUvVisitData()" v-t="'analysis.title4'">UV</span>
                    <span :class="{'selected':active==2}" @click="active=2;getPvUvVisitData()" v-t="'analysis.title5'">PV</span>
                </div>
                <div class="dataItem">
                    <div class="item">
                        <p  v-t="'analysis.table1'">Total</p>
                        <h5>{{visitData.totalVisit || 0}}</h5>
                    </div>
                    <div class="item">
                        <p  v-t="'analysis.table2'">Today</p>
                        <h5>{{visitData.dayVisit || 0}}</h5>
                    </div>
                    <div class="item">
                        <p  v-t="'analysis.table3'">This Week</p>
                        <h5>{{visitData.weekVisit || 0}}</h5>
                    </div>
                    <div class="item">
                        <p  v-t="'analysis.table4'">This Month</p>
                        <h5>{{visitData.monthVisit || 0}}</h5>
                    </div>
                </div>
            </div>
            <div class="look">
                <span class="txt" @click="showFlag1=true" v-t="'analysis.title6'">View Taffic Trends</span>
                <my-dailog v-model:show="showFlag1" :showtopclose="true" width="70%">
                    <div class="ads-fx-chart-box">
                        <uv-pv-chart :objectId='adPlaceId' :visitTypeCode='6' :operateType='11' gridBottom='50px'/>
                    </div>
                </my-dailog>
            </div>
            <div class="itembox">
                <div class="time time2"  v-t="'analysis.title7'">Advertising Reward Distribution Statistics</div>
                <div class="dataItem" v-if="awards.todayGrantBonus">
                    <div class="item">
                        <p v-t="'analysis.table1'">Total</p>
                        <h5>{{awards.totalGrantBonus.decimalTwoString || 0}}</h5>
                    </div>
                    <div class="item">
                        <p v-t="'analysis.table2'">Today</p>
                        <h5>{{awards.todayGrantBonus.decimalTwoString || 0}}</h5>
                    </div>
                    <div class="item">
                        <p v-t="'analysis.table3'">This Week</p>
                        <h5>{{awards.weekGrantBonus.decimalTwoString || 0}}</h5>
                    </div>
                    <div class="item">
                        <p v-t="'analysis.table4'">This Month</p>
                        <h5>{{awards.monthGrantBonus.decimalTwoString || 0}}</h5>
                    </div>
                </div>
            </div>
            <div class="look">
                <span class="txt" @click="showFlag2=true" v-t="'analysis.title8'">View Reward Distribution Trends</span>
                <my-dailog v-model:show="showFlag2" :showtopclose="true" width="70%">
                    <div class="jlffqsstbox2">
                        <reward-provide-trend-chart id="jlffqs2" :objectId="adPlaceJobRecordId"/>
                    </div> 
                </my-dailog>
            </div>
        </template>
        <div class="nomyads" v-else v-t="'dataNo'">No Data
        </div>
    </div>
</template>

<script>
import { reactive,toRefs,getCurrentInstance,computed } from 'vue'
import {useRoute,useRouter} from 'vue-router'
import { useStore } from 'vuex'
import myDailog from '@/components/myDailog.vue'
import uvPvChart from '@/components/uvPvChart.vue'
import rewardProvideTrendChart from '../../components/adDetail/rewardProvideTrendChart.vue'
import { useI18n } from 'vue-i18n'
export default {
    components:{
       myDailog,
       uvPvChart,
       rewardProvideTrendChart
    },
    props:{

    },
    setup(props,context){
        const router = useRouter()
        const route = useRoute()
        const store = useStore()
        const {proxy} = getCurrentInstance()
        const {t} = useI18n()

        const state = reactive({
            showFlag1:false,
            showFlag2:false,
            userInfo:computed(()=>store.state.base.userInfo),
            awards:{},
            visitData:{},
            active:1,
            adPlaceJobRecordId:'',
            adPlaceId:'',
            adPlaceJobId:''
        })

        const getAdAnalysData = async(id)=>{
            const res = await store.dispatch("ad/get_award_statistics", {
                adPlaceJobRecordId: state.adPlaceJobRecordId,
                walletAddress: state.userInfo.walletAddress
            });
            if(res.success){
                state.awards = res.data || {}
            }
        }
          const  getTimes=()=>{
                let date = new Date()
                return date.getFullYear()+'-'+getNumber(date.getMonth()+1)+'-'+getNumber(date.getDate())+' '+getNumber(date.getHours())+':'+getNumber(date.getMinutes()) 
        }
         const  getNumber=(val)=>{
             if(val>=10){
                 return val
             }else{
                 return '0'+val
             }
         }
        const getPvUvVisitData = (id)=>{
            store.dispatch('base/visit_statistics',{
                objectId:state.adPlaceId,
                objectTwoId:state.adPlaceJobId,
                operateType:state.active,  //访问量：1-UV,2-PV，趋势图：11-小时，5-天，2-月
                visitTypeCode:6
            }).then(res =>{
                state.visitData = res.data || {}
            })
        }

        const gettjData = (item)=>{ // 父组件调用
            console.log("YYY-item",item)
            state.adPlaceJobRecordId = item.adPlaceJobId
            state.adPlaceId = item.adPlaceId
            state.adPlaceJobId = item.adPlaceJobId
            getAdAnalysData()
            getPvUvVisitData()
        }

        return{
            ...toRefs(state),
            gettjData,
            getAdAnalysData,
            getPvUvVisitData,
            getTimes,
            getNumber
        }
    }
}
</script>

<style lang="scss" scoped>
    .alDataBox{
        font-family: Inter-Medium, Inter;
        font-weight: 500;
        color: #FFFFFF;
        font-size: 22px;
        line-height: normal;
        .itembox{
            padding: 10px;
            background: rgba(12,132,217,0.5000);
            .time{
                font-size: 22px;
                color: #fff;
                line-height: normal;
                &.time2{
                    border-bottom: 4px solid #2B8EC6;
                    padding: 5px 0 10px 0;
                }
            }
            .tabBox{
                display: flex;
                height: 60px;
                line-height: 60px;
                span{
                    flex: 1;
                    color: #2B8EC6;
                    font-size: 24px;
                    font-weight: bold;
                    text-align: center;
                    position: relative;
                    z-index: 10;
                    &::after{
                        content: '';
                        position: absolute;
                        left: 0;
                        bottom: 0;
                        width: 100%;
                        height: 4px;
                        background: #2B8EC6;
                    }
                    &+span{
                        margin-left: 5px;
                    }
                    &.selected{
                        color: #67F8FF;
                        &::after{
                            background:#67F8FF;
                        }
                    }
                }
            }
            .dataItem{
                display: flex;
                height: 80px;
                margin: 10px 0 0 0;
                .item{
                    flex: 1;
                    text-align: center;
                    p{
                        font-size: 22px;
                        color: #8AB3DD;
                        padding: 3px 0 0 0;
                        margin: 0;
                        line-height: normal;
                        
                    }
                    h5{
                        font-size: 26px;
                        line-height: normal;
                        padding: 5px 0 0 0;
                        margin: 0;
                        color: #fff;
                    }
                }
            }
        }
        .look{
            .txt{
                display: block;
                text-align: center;
                line-height: normal;
                font-size: 24px;
                font-weight: 500;
                color: #67F8FF;
                text-decoration: underline;
                padding: 15px 0;
            }
            
        }
        .nomyads{
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 22px;
            color: #FFFFFF;
            font-family: Inter-Medium, Inter;
            font-weight: 500;
            padding: 100px 0 0 0;
        }
    }
    .ads-fx-chart-box{
        height: 600px;
    }
    .jlffqsstbox2{
        height: 600px;
    }
</style>